<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
 <link href="assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="css/style.css"/>
        <link rel="stylesheet" href="assets/css/ace.min.css" />
        <link rel="stylesheet" href="assets/css/font-awesome.min.css" />
        <link href="Widget/icheck/icheck.css" rel="stylesheet" type="text/css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
	    <script src="js/jquery-1.9.1.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
        <script src="assets/js/typeahead-bs2.min.js"></script>

		<!-- page specific plugin scripts -->
		<script src="assets/js/jquery.dataTables.min.js"></script>
		<script src="assets/js/jquery.dataTables.bootstrap.js"></script>
        <script type="text/javascript" src="js/H-ui.js"></script>
        <script type="text/javascript" src="js/H-ui.admin.js"></script>
        <script src="assets/layer/layer.js" type="text/javascript" ></script>
        <script src="assets/laydate/laydate.js" type="text/javascript"></script>
         <script src="assets/dist/echarts.js"></script>
         <script src="js/lrtk.js" type="text/javascript"></script>
<title>品牌管理</title>
</head>

<body>
<div class="page-content clearfix">
  <div id="brand_style">
     <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:;"  title="添加品牌" class="btn btn-warning Order_form"><i class="icon-plus"></i>添加品牌</a>
       </span>
       <span class="r_f">共：<b>234</b>个品牌</span>
     </div>
     <!--品牌列表-->
      <div class="table_menu_list">
       <table class="table table-striped table-bordered table-hover" id="sample-table">
		<thead>
		 <tr>
				<th width="80px">ID</th>
				<th width="130px">游戏名</th>
				<th width="120px">效果图</th>
				<th width="120px">链接地址</th>
				<th width="200px">操作</th>
			</tr>
		</thead>
	<tbody>
        </tbody>
        </table>
        </div>
     </div>

  </div>
</div>
<!-- 添加产品-->
<form action="" method="post" class="form form-horizontal" id="form-adv-add" style="display:none;">
		<div class="clearfix cl">
         <label class="form-label col-2"><span class="c-red">*</span>游戏名</label>
		 <div class="formControls col-10">
		    <select name="goods_id" id="goods_id">

            </select>
		 </div>
		</div>
		<div class="clearfix cl">
         <label class="form-label col-2"><span class="c-red">*</span>图片：</label>
            <div class="formControls col-10"><input type="file" value="" placeholder="" id="" name="file"></div>
        </div>
	</form>


	<!-- 编辑产品-->
    <form action="" method="post" class="form form-horizontal" id="form-adv-edit" style="display:none;">
    		<div class="clearfix cl">
             <label class="form-label col-2"><span class="c-red">*</span>游戏名</label>
    		 <div class="formControls col-10">
    		    <select name="goods_id" id="goods_id">

                </select>
    		 </div>
    		</div>
    	</form>
</body>
</html>
<script>


// //初始化宽度、高度
//  $(".chart_style").height($(window).height()-215);
//   $(".table_menu_list").height($(window).height()-215);
//   $(".table_menu_list ").width($(window).width()-440);
//   //当文档窗口发生改变时 触发
//     $(window).resize(function(){
// 	 $(".chart_style").height($(window).height()-215);
// 	 $(".table_menu_list").height($(window).height()-215);
// 	 $(".table_menu_list").width($(window).width()-440);
// 	});
	//图层隐藏限时参数
$(function() {
	$("#category").fix({
		float : 'left',
		//minStatue : true,
		skin : 'green',
		durationTime :false,
		stylewidth:'400',
		spacingw:30,//设置隐藏时的距离
	    spacingh:440,//设置显示时间距
	});
});



function queryAll(){
    $.ajax({
        type:"post",
        url:"goods_adv_map/goodsAdvMapQuery.php",
        datatype:"json",
        success:function(data){
            console.log(data);
            createDom(data);
        }
    });
}
queryAll();
function createDom(nodes){
    var dom = "";
    for(let i=0,len=nodes.length;i<len;i++){
        let value = nodes[i];
        dom+=' <tr>'
        dom+='  <td width="80px">'+value['id']+'</td>'
        dom+='  <td width="50px">'+value['goods_name']+'</td>'
        dom+='  <td><img src="'+value['imgUrl']+'"  width="130"/></td>'
        dom+='  <td width="100px"><a href="'+value['imgUrl']+'">'+value['imgUrl']+'</a></td>'
        dom+='  <td class="td-manage">'
        dom+='  <a title="编辑" href="javascript:;"  data-index="'+value['id']+'" class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a>'
        dom+='  <a title="删除" href="javascript:;"  data-index="'+value['id']+'"  class="btn btn-xs btn-warning" ><i class="icon-trash  bigger-120"></i></a>'
        dom+='  </td>'
        dom+='</tr>'
    }
    $("tbody").eq(0).html(dom);
}
// 添加
 $(".Order_form").eq(0).on("click",function(){
    $.ajax({
        type:"post",
        url:"goods_adv_map/returnGoodsName.php",
        datatype:"json",
        success:function(data){
            console.log(data);
            var options = "";
            let value = null;
            for(let i=0,len=data.length;i<len;i++){
                value = data[i];
                options+='<option value="'+value["id"]+'">'+value["goods_name"]+'</option>';
            }
            $("select").eq(0).html(options);
        }

    });
    layer.open({
            type: 1,
            title: '添加产品效果图',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area : ['800px' , ''],
            content:$('#form-adv-add'),
            btn:['提交','取消'],
            yes:function(index,layero){
//     		    console.log(document.getElementById("form-goods-add"));
            var formdata = new FormData(document.getElementById("form-adv-add"));
                $.ajax({
                    url:"goods_adv_map/goodsAdvMapInsert.php",
    // 		        async: false,//同步上传
                    cache: false,//上传文件无需缓存
                    processData: false,  // 不处理数据
                    contentType: false, // 不设置内容类型
                    type:"post",
                    datatype:"json",
                    data:formdata,
                    success:function(data){
                        console.log(data);
                        layer.msg(data.msg);
                        queryAll();
                    },
                    error:function(e){
                        console.log(e);
                    }
                });
                layer.close(index);

            }
        });
 });
// 删除
 $("tbody").eq(0).on("click",".btn-warning",function(){
     var index = $(this).data("index");
     $.ajax({
         type:"post",
         url:"goods_adv_map/goodsAdvMapDel.php",
         data:{
             id:index,
         },
         datatype:"json",
         success:function(data){
             console.log(data);
             layer.msg(data.msg);
             queryAll();
         }
     });
 })
 // 编辑
 $("tbody").eq(0).on("click",".btn-info",function(){
     var index = $(this).data("index");
     $.ajax({
         type:"post",
         url:"goods_adv_map/goodsAdvMapQueryOne.php",
         data:{
             id:index,
         },
         datatype:"json",
         success:function(data){
             console.log(data);
              var options = "";
             let value = null;
             for(let i=0,len=data[1].goodsName.length;i<len;i++){
                 value = data[1].goodsName[i];
                 options+='<option value="'+value["id"]+'">'+value["goods_name"]+'</option>';
             }
             $("select").eq(1).html(options);

             inpdata = data[0];
             // 写入表单值
                $("select").eq(1).find('option').each(function(){
                        if($(this).val() ==data[0]['goods_id']){
                            this.selected =true;
                        }
                    });
              layer.open({
                         type: 1,
                         title: '编辑产品',
                         maxmin: true,
                         shadeClose: false, //点击遮罩关闭层
                         area : ['800px' , ''],
                         content:$('#form-adv-edit'),
                         btn:['提交','取消'],
                         yes:function(index,layero){

                         $.ajax({
                             url:"goods_adv_map/goodsAdvMapEdit.php",
                             type:"post",
                             datatype:"json",
                             data:{
                                id:index,
                                goods_id:$("#goods_id").val()

                             },
                             success:function(data){
                                 console.log(data);
                                 layer.msg(data.msg);
                                 queryAll();
                             },
                             error:function(e){
                                 console.log(e);
                             }
                         });
                         layer.close(index);

                     }
                     });
         }
     });
 })

</script>
